import type { LayoutServerLoad } from './$types';
import {reqUserInfo} from '$lib/api/server/sys/user/index';
import type { Option } from '$lib/components/Basic/Popover/types';

export type UserInfo = {
	userId: Number,
	userName: String,
	forDeptId: Number
}

export const load: LayoutServerLoad = async ( event ) => {
	const result = (await reqUserInfo(event)) as unknown as any;	
	const menuItems = result.menus[0].children as Option[];
	const userInfo = {
		userId: result.userId,
		userName: result.userName,
		forDeptId: result.forDeptId
	}
	return {
		menuItems: menuItems || [], // 兜底空数组，避免组件中处理 undefined		
		userInfo: userInfo,
		codes: result.codes,
		funcCodes:result.funcCodes
	};
};
